package stub;

import java.util.Iterator;
import java.util.List;

import data.College;
import data.CollegePlan;
import data.Course;
import data.Student;
import data.Teacher;
import dataservice.college_dataservice.College_dataservice;
import enum_pck.ResultMessage;

public class College_dataservice_stub implements College_dataservice{
	College college;
	CollegePlan plan;
	List<Course> list;
	List<Teacher> teachers;
	List<Student> students;
	
	public College_dataservice_stub(College college, CollegePlan plan,
			List<Course> list, List<Teacher> teachers, List<Student> students) {
		super();
		this.college = college;
		this.plan = plan;
		this.list = list;
		this.teachers = teachers;
		this.students = students;
	}

	@Override
	public College findCollege(String Id) {
		// TODO Auto-generated method stub
		if(Id.equals(college.getCollegeID())){
			return college;
		}
		else{
		return null;
		}
	}

	@Override
	public ResultMessage updatePlan(String collegeID, CollegePlan plan) {
		// TODO Auto-generated method stub
		if(collegeID.equals(college.getCollegeID())){
			this.plan = plan;
			return ResultMessage.Success;
		}
		else{
			return ResultMessage.IdNotExist;
		}
	}

	@Override
	public ResultMessage insertCourse(String collegeID,Course c) {
		if(collegeID.equals(college.getCollegeID())){
			list.add(c);
			return ResultMessage.Success;
		}else{
			return ResultMessage.IdNotExist;
		}
	}

	@Override
	public ResultMessage updateCourse(String courseID, Course c) {
		// TODO Auto-generated method stub
		for(Course cou : list){
			if(cou.getCourseBasicInfo().getCourseId().equals(courseID)){
				list.set(list.indexOf(cou), c);
				return ResultMessage.Success;	
			}
		}
		return ResultMessage.IdNotExist;
	}

	@Override
	public ResultMessage insertTeacher(Teacher t) {
		for( Teacher tch : teachers){
			if(tch.getTeacherID().equals(t.getTeacherID())){
				return ResultMessage.IdExist;	
			}
		}
		return ResultMessage.Success;
	}

	@Override
	public ResultMessage deleteTeacher(String teacherID) {
		Iterator<Teacher> i = teachers.iterator();
		while(i.hasNext()){
			Teacher tch = i.next();
			if(tch.getTeacherID().equals(teacherID)){
				i.remove();
				return ResultMessage.Success;	
			}
		}
		return ResultMessage.IdNotExist;
	}

	@Override
	public ResultMessage deleteStudent(String studentID) {
		Iterator<Student> i = students.iterator();
		while(i.hasNext()){
			Student std = i.next();
			if(std.getStudentID().equals(studentID)){
				i.remove();
				return ResultMessage.Success;	
			}
		}
		return ResultMessage.IdNotExist;
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		System.out.println("initing...");
		System.out.println("already inited");
	}

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		System.out.println("successfully finish");
	}
}
